var sublist=[];
var subvlist=[];
var tasklist;
//分数区间
var l1=0,l2=0,l3=0,l4=0,l5=0,l6=0,l7=0;
$(function  () {

    //按照ID取回所有作业
    var uid = $.cookie("lid");
    
    var overliu=0;
    var overba=0;
    $.ajax({
            url: ipurl+'/task/gettaskbyuid',
            data: {
                uid:uid
            },
            type: "POST",
            //dataType: "json",
            success:function(resultper){
                tasklist = resultper.data.results;
                console.log(tasklist)
                $("#totalcount").html(tasklist.length);
                for(var i=0;i<tasklist.length;i++){
                    if(tasklist[i].achievement>60){
                        overliu+=1;
                    }
                    if(tasklist[i].achievement>80){
                        overba+=1;
                    }
                    if(tasklist[i].achievement>30&&tasklist[i].achievement<40){
                        l1+=1;
                    }else if(tasklist[i].achievement>60&&tasklist[i].achievement<50){
                        l2+=1;
                    }else if(tasklist[i].achievement>50&&tasklist[i].achievement<60){
                        l3+=1;
                    }else if(tasklist[i].achievement>60&&tasklist[i].achievement<70){
                        l4+=1;
                    }else if(tasklist[i].achievement>70&&tasklist[i].achievement<80){
                        l5+=1;
                    }else if(tasklist[i].achievement>80&&tasklist[i].achievement<90){
                        l6+=1;
                    }else if(tasklist[i].achievement>90&&tasklist[i].achievement<100){
                        l7+=1;                        
                    }
                }
                $("#totalliu").html(overliu);
                $("#totalba").html(overba);
                initline();
                getss();
            },
            complete: function(data) {

            }
        });

        
   
})


function getss(){
//获取学科
$.ajax({
    url: ipurl+'/subject/get',
    type: "POST",
    //dataType: "json",
    success:function(resultper){
        var subl = resultper.data.results;
        for(var n =0;n<subl.length;n++){
            sublist.push(subl[n].name);
            var subv = {
                value:0,
                name:subl[n].name
            };
            subvlist.push(subv);
        }
        console.log(sublist);
        initp();


    },
    complete: function(data) {

    }
});
}


function initline(){
    var linelist=[];
    linelist.push(l1);
    linelist.push(l2);
    linelist.push(l3);
    linelist.push(l4);
    linelist.push(l5);
    linelist.push(l6);
    linelist.push(l7);

    var dom = document.getElementById("container");
var myChart = echarts.init(dom);
var app = {};
option = null;
option = {
    color: ['#3398DB'],
    tooltip: {
        trigger: 'axis',
        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: [
        {
            type: 'category',
            data: ['30-40', '40-50', '50-60', '60-70', '70-80', '80-90', '90-100'],
            axisTick: {
                alignWithLabel: true
            },
            axisLine:{
                lineStyle: {
                    color: '#fff',
                    width:2
                }   
            }
        }
    ],
    yAxis: [
        {
            type: 'value',
            axisLine:{
                lineStyle: {
                    color: '#fff',
                    width:2
                }   
            } 
        }
    ],
    series: [
        {
            name: '作业数量',
            type: 'bar',
            barWidth: '60%',
            data: linelist
        }
    ]
    };
    ;
    if (option && typeof option === "object") {
        myChart.setOption(option, true);
    }
}


function initp(){


    for(var i=0;i<tasklist.length;i++){
       for(var m = 0;m<subvlist.length;m++){
        if(tasklist[i].name==subvlist[m].name){
            subvlist[m].value+=1;
        }
       }
    }

    console.log(sublist);
    console.log(subvlist);

    //饼状图
    var dom1 = document.getElementById("pie");
    var myChart1 = echarts.init(dom1);
    var app1 = {};
    option1 = null;
    option1 = {
        title: {
            text: '各科作业比例',
            left: 'center',
            textStyle:{
                color:'#fff',
                fontweight:'blod',
                fontSize:22
            }
        },
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            data: sublist,
            textStyle:{
                color:'#fff',
                fontweight:'bold',
                fontSize:22
            }
        },
        series: [
            {
                name: '科目',
                type: 'pie',
                radius: '80%',
                center: ['50%', '60%'],
                data:subvlist,
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    ;
    if (option1 && typeof option1 === "object") {
        myChart1.setOption(option1, true);
    }

}

